<template>
	<view class="content">
		<view class="topBox">
			<view>当期分红金额</view>
			<view class="moneyTxt">{{fenhong.dqyue}}</view>
			<view class="moneyTxt" >上一期分红金额</view>
			<view class="moneyTxt">{{fenhong.sqyue}}</view>
			<view class="moneyTxt" v-if="fenhong.fh_status==1">您已分红</view>
			<view class="moneyTxt" v-if="fenhong.fh_status==1">{{fenhong.yfhje}}</view>
			<view style="width: 100%;overflow: hidden;">
				<button v-if="fenhong.fh_status==0" @click="jihuofenhong()">激活</button>
				<button v-if="fenhong.fh_status==1">已激活</button>
				<button v-if="fenhong.fh_status==2">已完成分红</button>
			</view>

		</view>
		<view class="top-line item-flex ">
		</view>
		<view class="list">
			<view class="line item-flex" v-for="(item,index) in fenhong.log">
				<view style="text-align: left;width: 70%;">
					<view >
						{{item.note}}
					</view>
					<view style="color: #999;font-size: 28rpx;">{{item.time}}</view>
				</view>
				<view style="text-align: right;width: 30%;">
					
					<view class="item-flex flex-center">
						<view style="color:red ;" v-if="item.status==1">+{{item.money}}</view>
						<view style="color: black;" v-else>-{{item.money}}</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="status" :content-text="contentText" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				startDate: "2021-09",
				endDate: "2021-10",
				date: "2021-10",
				seePoup: false,
				fenhong: '',
				userinfo: '',
				number: '',
				seePoups: false,
				uid: '',
				path: '../static/shangchuan.png',
				imgshow:false,
				value: 0,
				range: [{
						value: 0,
						text: "请选择提现方式"
					},
					{
						value: 1,
						text: "微信"
					},
					{
						value: 2,
						text: "支付宝"
					},
				],
				total: 0, //数据量
				current_page: 1, //当前页码
				last_page: 1, //总页码
				status: 'more',
				contentText: {
					contentdown: ' ',
					contentrefresh: '加载中',
					contentnomore: ''
				}
			}
		},
		onLoad() {
			const res = uni.getStorage({
				key: 'userInfo',
				success: (res) => {
					
					if (res.data) {
						//console.log(res.data,'ssssss')
						this.userinfo = res.data
						if (this.userinfo.member_id) {
							//this.getuseragain();
							// this. url="http://pth5.njkw668.com/#/pages/user/user?&pid="+this.userinfo.member_id
						}
					} else {
						window.location.href =
							'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9a8339b68f86cd01&redirect_uri=http%3A%2F%2Fpth5.njkw668.com%2F%23%2Fpages%2Fpublic%2Flogin&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect';
					}
				},
				fail: (res) => {
					window.location.href =
						'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9a8339b68f86cd01&redirect_uri=http%3A%2F%2Fpth5.njkw668.com%2F%23%2Fpages%2Fpublic%2Flogin&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect';
				}
			});
			this.getuserfenhong()

		},
		onReachBottom() {
			//判断是否最后一页
			if (this.current_page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				console.log(this.current_page, 'sssss')
				this.current_page = this.current_page + 1; //页码+1
				
				this.status = 'loading';
				this.getuserfenhong()
			}
		},
		
		methods: {
			async jihuofenhong() {
				if(this.userinfo.type<1){
					uni.showToast({
						title: '暂无资格',
						icon: 'none'
					})
				}
				const res = await this.$myRequest({
					url: 'index.php/api/user/jihuofenhong',
					method: "POST",
					data: {
						"member_id": this.userinfo.member_id,
					},
				})
				if (res.status == 200) {
					uni.showToast({
						title: res.data,
						icon: 'none'
					})
					setTimeout(() => {
					    uni.reLaunch({
					    	url: '/pages/user/fenhongindex'
					    })
					}, 2000)
				}
			},
			async getuserfenhong() {
				//console.log(this.userinfo,'aaaaaaaaaa')
				const res = await this.$myRequest({
					url: 'index.php/api/user/fenhongindex',
					method: "POST",
					data: {
						"member_id": this.userinfo.member_id,
						'page': this.current_page
					},
				})
				uni.stopPullDownRefresh();
				if(this.current_page==1){
					
					this.fenhong = res.data
					this.fenhong.log = res.data.log.data
					this.total = res.data.log.total; //数据量
					// this.current_page = res.data.log.current_page; //当前页码
					this.last_page = res.data.log.last_page; //总页码
					this.status = res.data.log.total == 0 ? 'noMore' : 'more';
				}else{
					console.log(res.data.log.current_page,'1')
					this.fenhong.log = this.fenhong.log.concat(res.data.log.data); //数据 追加
					this.total = res.data.log.total; //数据量
					// this.current_page = res.data.log.current_page; //当前页码
					this.last_page = res.data.log.last_page; //总页码
					this.status = res.data.log.current_page==res.data.log.last_page ? 'noMore' : 'more';
				}
				
				
				
			}
		}
	}
</script>

<style>
	.postformcontentlevel{
		display: flex;
		height: 100rpx;
		line-height: 100rpx;
		width: 90%;
		margin: 0 auto;
	}
	.text-sm2{
		width: 70%;
		margin: 0 auto;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background-repeat: no-repeat;
		background-size:100% 100%;
	}
	.text-sm{
		width: 50%;
		margin: 0 auto;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background-repeat: no-repeat;
		background-size:20% ;
		background-position-x: left;
		background-position-y: center;
	}
	.item-flex {
		display: flex;
		align-items: center;
		/* height: 50rpx; */
		line-height: 60rpx;
	}

	.flex-center {
		justify-content: center;
	}

	.flex-around {
		display: flex;
		justify-content: space-around;
	}

	page {
		background: #f5f5f5;
	}

	.topBox {
		width: 100%;
		padding: 10rpx 3%;
		font-size: 32rpx;
		color: #ececec;
		height: 400rpx;
		background: linear-gradient(to right, #3464E3, #1A55EA);
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
	}

	.topBox button {
		font-size: 32rpx;
		float: left;
	}

	.moneyTxt {
		font-size: 32rpx;
		color: #fff;
		font-weight: bold;
	}

	.top-line {
		width: 100%;
		flex: 1;
		padding: 10rpx 3%;
		height: 72rpx;
		line-height: 72rpx;
	}

	.list {
		width: 100%;
		padding: 0 3%;
		background: #fff;
	}

	.list .line:last-child {
		border: none
	}

	.line {
		width: 100%;
		border-bottom: 2rpx solid #ebebeb;
		text-align: left;
	}

	.line view,
	.sumTxt view {
		width: 100%;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}

	.line image {
		width: 48rpx;
		border-radius: 50%;
		margin-right: 10rpx;
	}

	.changeMonth {
		width: 30%;
		margin-right: 10%;
		position: relative;
	}

	.changeMonth picker {
		width: 100%;
	}

	.changeMonth image {
		width: 32rpx;
		position: absolute;
		right: 0;
		top: 20rpx;
	}

	.changeIcon {
		width: 32rpx;
	}

	.sumTxt {
		width: 60%;
		font-size: 28rpx;
		color: #999;
		display: flex;
		
		    flex-direction: row;
	}

	.marke {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 990;
		background: rgba(0, 0, 0, 0.7);
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.withdraw {
		width: 80%;
		background: #fff;
		border-radius: 20rpx;
		position: relative;
	}

	.markeTitle {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 32rpx;
		color: #333;
		text-align: center;
		background: #f5f5f5;
		border-radius: 20rpx 20rpx 0 0;
	}

	.moneyBox {
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		border-bottom: 2rpx solid red;
		margin: 20rpx 5%;
		text-align: center;
		font-size: 42rpx;
		font-weight: bold;
		color: red;
	}

	.tips {
		font-size: 30rpx;
		color: #bebebe;
		text-align: center;
		font-weight: normal;
	}

	.withdraw button {
		width: 90%;
		margin: 20rpx 5%;
		margin-top: 40rpx;
		font-size: 32rpx;
		height: 88rpx;
		line-height: 88rpx;
		border: none;
		background: #007AFF;
		color: #fff;
	}

	.withdraw button::after {
		border: none;
	}

	.cancel {
		position: absolute;
		top: -20rpx;
		right: -20rpx;
		background: #fff;
		border-radius: 50%;
		z-index: 999;

	}
</style>